home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / rjs.lha / RJS / String / src / StringScan.C < prev    next >
C/C++ Source or Header  |  1991-06-14  |  1KB  |  50 lines

  1. #include "String.h"
  2.  
  3. const FALSE=0,TRUE=1;
  4.  
  5. int RJS_StringScan::operator()(RJS_String &match)
  6. {
  7. int curr_pos;
  8. int ss_pos, ss_len;
  9.  
  10.   if ( pos >= str->length()) {
  11.     match=NullRJS_String;
  12.     if (st==ByField && !lf) { lf=1; return TRUE; }
  13.     return FALSE;
  14.   }
  15.   
  16.   curr_pos=pos;
  17.  
  18.   switch(st) {
  19.     case ByField:
  20.         ss_pos=ss->search(str->substr(curr_pos),ss_len);
  21.         if (ss_len==0) { // no more fields, return rest of string
  22.             pos+=str->length()-curr_pos;
  23.             match=str->substr(curr_pos);
  24.             lf=1; // set last field flag
  25.             return TRUE;
  26.         }
  27.         if (ss_pos!=0) {
  28.             pos += ss_pos+ss_len;
  29.             match=str->substr(curr_pos,ss_pos);
  30.             return TRUE;
  31.         } else {        // null field
  32.             pos += ss_len;
  33.             match=NullRJS_String;
  34.             return TRUE;
  35.         }
  36.         break    ;
  37.     case ByMatch:
  38.                 ss_pos=ss->search(str->substr(curr_pos),ss_len);
  39.         if (ss_len==0) { match=NullRJS_String; return FALSE; }
  40.         curr_pos+=ss_pos;
  41.         pos = curr_pos+ss_len;
  42.         match=str->substr(curr_pos,ss_len);
  43.         return TRUE;
  44.         //break;
  45.     default:
  46.         match=NullRJS_String;
  47.         return FALSE;
  48.     } // eos
  49. }
  50.